package uscdb.controller;

import org.apache.log4j.Logger;

import java.io.File;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import uscdb.pageModel.Json;
import uscdb.service.PoiService;


@Controller
@RequestMapping("/importController")
public class ImportController extends BaseController {
	/**
	* Logger for this class
	*/
	private static final Logger logger = Logger.getLogger(ImportController.class);
	
	private File file;

	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}
	
	@Autowired
	private PoiService poiService;
	
	@ResponseBody
	@RequestMapping("/importProductExcel")
	public Json importProductExcel(){
		Json json = new Json();
		try {
			poiService.importProductExcel(file);
			json.setSuccess(true);
			json.setMsg("导入成功");
		} catch (Exception e) {
			json.setMsg("导入失败");
			logger.error(e.getMessage(), e);
		}
		return json;
	}
	
}
